<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("机构列表")}</title>
<link href="/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/jquery.js"></script>
<script type="text/javascript" src="/resources/js/base/dialog.js"></script>
<script type="text/javascript" src="/resources/js/base/request.js"></script>
<script type="text/javascript" src="/resources/js/base/global.js"></script>
<script type="text/javascript"
	src="/resources/js/reference/jquery.validate.js"></script>
<script type="text/javascript" src="/resources/js/reference/mmGrid.js"></script>
<link href="/resources/css/mmGrid.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	function addFun() {
		var rows = $mmGrid.selectedRows();
		var ids_str = '';
		if (rows.length > 0) {
			ids_str = 'ids=' + rows[0].id
		}
		create_iframe('add.jhtml?' + ids_str);
	}
	function getChildren(e) {
		var status = $(e).attr("data-status");
		var id = $(e).attr("data-id");
		var rowIndex = $(e).closest("tr").index();
		var oId;
		$idThis = $(".mmGrid").find(".id" + id)
		if (status == "") {
			rowIndex = parseInt(rowIndex) + 1;
			$(e).attr("data-status", "1");
			ajaxSubmit($(id), {
				method : 'post',
				url : 'getChildren.jhtml?id=' + id,
				callback : function(data) {
					var uid
					var item = data.objx;
					if ($(e).hasClass("topNav")) {
						uid = 'id' + $(e).attr("data-id");
					} else {
						uid = $(e).attr("data-class");
					}
					for (var i = 0; i < item.length; i++) {
						item[i].parent = id;
					}
					$mmGrid.addRow(item, rowIndex, uid);
					$("tr").removeClass("even");
					$("tr:nth-child(2n)").addClass("even");
				}
			})
			$(e).addClass("treeClose").removeClass("treeOpen")
		} else if (status == 1) {
			$idThis.closest("tr").hide();
			$(e).removeClass("treeClose").addClass("treeOpen")
			$(e).attr("data-status", "0");
			$("tr").removeClass("even");
			$("body").find("tr:visible:even").addClass("even");
		} else {
			$idThis.closest("tr").show();
			oId = $(".mmGrid").find(".id" + id + ".treeOpen").attr("data-id")
			$(".mmGrid").find(".id" + oId).closest("tr").hide();
			$(e).addClass("treeClose").removeClass("treeOpen")
			$(e).attr("data-status", "1");
			$("tr").removeClass("even");
			$("body").find("tr:visible:even").addClass("even");
		}
	}
	$()
			.ready(
					function() {
						var $listForm = $("#listForm");
						var $delete = $("#listTable a.delete");
						var $searchBtn = $("#searchBtn");
						var $hideShow = $("#hideShow");
						var $searchDiv = $("#searchDiv");
						/**初始化多选的下拉框*/
						initMultipleSelect();

						var cols = [
								{
									title : '${message("机构名称")}',
									name : 'name',
									align : 'left',
									renderer : function(val, item, rowIndex,
											obj) {
										var grade = item.grade;
										var style_str = 'margin-left: '
												+ (grade * 30) + 'px;';
										if (item.is_search == 1) {
											return '<a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='
													+ item.id
													+ '&flag=${flag}\')" class="red">'
													+ val + '</a>';
										} else {
											if (obj == undefined) {
												if (item.is_leaf == 1) {
													return '<span  style="'+style_str+' padding-left:30px"><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='
															+ item.id
															+ '\')" class="red">'
															+ val
															+ '</a></span>';
												} else {
													return '<span style="'
															+ style_str
															+ '" class="treeOpen topNav open" onclick="getChildren(this)" data-id="'
															+ item.id
															+ '" data-rowIndex ="'
															+ rowIndex
															+ '" data-status=""></span><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='
															+ item.id
															+ '\')" class="red">'
															+ val + '</a>';
												}
											} else {
												if (item.is_leaf == 1) {
													return '<span  style="'+style_str+' padding-left:30px" class="'+obj+'" ><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='
															+ item.id
															+ '\')" class="red">'
															+ val
															+ '</a></span>';
												} else {
													return '<span style="'
															+ style_str
															+ '" onclick="getChildren(this)" class="treeOpen '
															+ obj
															+ '" data-class="'
															+ obj
															+ ' id'
															+ item.id
															+ '"  data-id="'
															+ item.id
															+ '" data-rowIndex ="'
															+ rowIndex
															+ '" data-status=""></span><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='
															+ item.id
															+ '\')" class="red">'
															+ val + '</a>';
												}
											}
										}
									}
								},
								{ title:'${message("机构编号")}', name:'sn' , align:'center'},
								{
									title : '${message("机构类型")}',
									name : 'type',
									align : 'center',
									renderer : function(val) {
										var types = {'0':'${message("公司")}','1':'${message("客户")}','2':'${message("油库")}'};
										if(val!=null){
											return types[val];
										}
									}
								},
								{
									title : '${message("12057")}',
									name : 'is_enabled',
									align : 'center',
									renderer : function(val) {
										if (val == true) {
											return '<span class="trueIcon">&nbsp;</span>';
										} else {
											return '<span class="falseIcon">&nbsp;</span>';
										}
									}
								}, {
									title : '${message("上级机构")}',
									name : 'tree_path_name',
									align : 'center'
								}, ];

						$mmGrid = $('#table-m1').mmGrid({
							autoLoad : true,
							multiSelect : false,
							fullWidthRows : true,
							cols : cols,
							url : 'list_data.jhtml',
							callback:function(){
					        	var e=$(".topNav");
					        	getChildren(e);
					        },
							params : function() {
								return $("#listForm").serializeObject();
							},
							plugins : [ $('#paginator').mmPaginator() ]
						});

					});
	function productCategoryImport(e) {
		excel_import(e, {
			title : '${message("机构导入")}',
			url : 'import_excel.jhtml',
			template : '/resources/template/product/productCategory.xls',
			callback : function() {
				$("#searchBtn").click();
			}
		})
	}
</script>
</head>
<body>
	<form id="listForm" action="list.jhtml" method="get">
		<div class="bar">
			<div class="buttonWrap">
			
				<a href="javascript:;" onclick="parent.change_tab(0,'add.jhtml',1)" class="iconButton" id="addButton">
					<span class="addIcon">&nbsp;</span>新增机构
				</a>
			
				<!--<a href="javascript:void(0);" id="importButton" class="iconButton" onclick="productCategoryImport(this)">
				<span class="importIcon">&nbsp;</span>${message("导入")}
			</a>-->
			</div>
			[#--搜索begin--]
			<div class="search-btn">
				<a href="javascript:;" id="searchBtn" class="iconButton">${message("1004")}</a>
			</div>
			<div id="searchDiv">
				<div id="search-content">
					<dl>
						<dt>
							<p>${message("机构名称")}：</p>
						</dt>
						<dd>
							<input class="text" maxlength="200" type="text"
								name="saleOrgName" btn-fun="clear">
						</dd>
					</dl>
					<dl>
						<dt>
							<p>${message("机构编号")}：</p>
						</dt>
						<dd>
							<input class="text" maxlength="200" type="text"
								name="sn" btn-fun="clear">
						</dd>
					</dl>
					<dl>
						<dt>
							<p>${message("12057")}：</p>
						</dt>
						<dd>
							<div class="checkbox-style">
								<a href="javascript:void(0);" onclick="clearText(this)"
									class="deleteText close"></a> <input type="text"
									class="text pointer doStatus" value="" autocomplete="off" />
								<div class="statusList cs-box" data-value="off">
									<label><input name="isEnabled" value="true"
										type="checkbox" class="check js-iname" />是</label> <label><input
										name="isEnabled" value="false" class="check js-iname"
										type="checkbox" />否</label>
								</div>
							</div>
						</dd>
					</dl>
				</div>
			</div>
		</div>
		[#--搜索end--]
		<div class="table-responsive">
			<table id="table-m1"></table>
			<div id="body-paginator" style="text-align: left;">
				<div id="paginator"></div>
			</div>
		</div>
	</form>
</body>
</html>